/*
 * Copyright 2003-2007 (c) Live Media Pty Ltd. <argot@einet.com.au> 
 *
 * This software is licensed under the Argot Public License 
 * which may be found in the file LICENSE distributed 
 * with this software.
 *
 * More information about this license can be found at
 * http://www.einet.com.au/License
 * 
 * The Developer of this software is Live Media Pty Ltd,
 * PO Box 4591, Melbourne 3001, Australia.  The license is subject 
 * to the law of Victoria, Australia, and subject to exclusive 
 * jurisdiction of the Victorian courts.
 */

package com.colony.container.simple;

import java.io.IOException;

import com.argot.TypeException;
import com.argot.TypeInputStream;
import com.argot.TypeOutputStream;
import com.argot.TypeReader;
import com.argot.TypeWriter;
import com.argot.common.BigEndianUnsignedShort;
import com.argot.remote.MetaLocation;


/**
 * This is the most basic form of location.  The object has only an integer id.
 */
public class SimpleLocation
implements MetaLocation
{
	public static final String TYPENAME = "index";
	
	private int _index;
	private String _host;
	
	public SimpleLocation( int index )
	{
		_index = index;
	}
	
	public SimpleLocation( int index, String host )
	{
		_index = index;
		_host = host;
	}

	public int getIndex() 
	{
		return _index;
	}
	
	
	public void setHost( String host )
	{
		_host = host;
	}
	public String getHost()
	{
		return _host;
	}
	
	public static class SimpleLocationReader 
	implements TypeReader 
	{
		public Object read(TypeInputStream in) 
		throws TypeException, IOException 
		{
			Integer i = (Integer) in.readObject( BigEndianUnsignedShort.TYPENAME );
			return new SimpleLocation( i.intValue() );
		}
	}

	public static class SimpleLocationWriter
	implements TypeWriter
	{
		public void write(TypeOutputStream out, Object o) 
		throws TypeException, IOException 
		{
			SimpleLocation loc = (SimpleLocation) o;
			out.writeObject( BigEndianUnsignedShort.TYPENAME, new Integer( loc._index ) );
		}
	}
}
